package com.baijing.springbootstudy.controller;

import com.baijing.spring_boot_starter_hello.HelloService;
import com.baijing.springbootstudy.config.AuthorSettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

//使用xml配置
//@ImportResource({"classpath:some-context.xml", "classpath:another-context.xml"})
@RestController
public class HelloController {

    //bean与配置文件参数绑定
    @Autowired
    private AuthorSettings authorSettings;

    //value与配置文件参数绑定
    @Value("${book.author}")
    private String bookAuthor;

    @Value("${book.name}")
    private String bookName;

    //自定义配置pom文件，也可与配置文件参数绑定
    @Autowired
    private HelloService helloService;

    @RequestMapping("/hello")
    String hello() {
        return "book name is: " + bookName + " and book author is: " + bookAuthor;
    }

    @RequestMapping("/author")
    String author() {
        return "author name is: " + authorSettings.getName() + " and author age is: " + authorSettings.getAge();
    }

    @RequestMapping("/autoConfig")
    String autoConfig() {
        return helloService.sayHello();
    }

}
